package files;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Scratch {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Pattern ps = Pattern.compile("!(\\S+)!");
		Matcher m = ps.matcher("500 !1234!abcd$4obal" +
				"\n510 !5678!asdf$4obal");
		StringBuffer output = new StringBuffer();
		while (m.find()) {
			m.appendReplacement(output, "\\$9$1\\$8");
		}
		m.appendTail(output);
		System.out.println(output.toString().trim()); //Remove trailing spaces

	}

}
